﻿#include "hemodialysisdialog.h"
#include "ui_hemodialysisdialog.h"

HemodialysisDialog::HemodialysisDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::HemodialysisDialog)
{
    UserData user;
    ui->setupUi(this);
    setWindowFlags(Qt::SplashScreen|Qt::FramelessWindowHint);
    ui->cleanBtn->setEnabled(false);
    ui->connectDBtn->setEnabled(false);
    ui->connectLBtn->setEnabled(false);
    ui->openBBtn->setEnabled(false);
    ui->DFFBtn->setEnabled(false);
    ui->progressBar->setValue(0);
    ui->progressBar_2->setValue(0);
    ui->progressBar_3->setValue(0);
    ui->progressBar_4->setValue(0);
    user.setName(QStringLiteral("张怡然"));
    user.setAge(25);
    ui->nameinfo->setText(QStringLiteral("姓名：")+user.getName());
    ui->ageinfo->setText(QString(QStringLiteral("年龄：%1")).arg(user.getAge()));
    drawRoundProgress();
    ui->startbBtn->setEnabled(false);
}

HemodialysisDialog::~HemodialysisDialog()
{
    delete ui;
}

void HemodialysisDialog::on_closeButton_clicked()
{

    close();
}

void HemodialysisDialog::on_checkBtn_clicked()
{
    m_timer=new QTimer(this);
    connect(m_timer,SIGNAL(timeout()),this,SLOT(updateProgress()));
    m_timer->start(100);
    ui->cleanBtn->setEnabled(true);

}
int pre=0;
void HemodialysisDialog::updateProgress(){
    if(pre-5>=100){
        return;
    }
    ui->myProgressBar->setValue(pre);
    pre+=5;

}

void HemodialysisDialog::on_cleanBtn_clicked()
{
    m_splash=new SplashProgressBar(5000,ui->progressBar,ui->connectLBtn);
    m_splash->show();
    m_splash->finish(this);
}

void HemodialysisDialog::on_connectLBtn_clicked()
{

    m_splash=new SplashProgressBar(5000,ui->progressBar_2,ui->connectDBtn);
    m_splash->show();
    m_splash->finish(this);
}

void HemodialysisDialog::on_connectDBtn_clicked()
{

    m_splash=new SplashProgressBar(5000,ui->progressBar_3,ui->openBBtn);
    m_splash->show();
    m_splash->finish(this);
}

void HemodialysisDialog::on_openBBtn_clicked()
{

    m_splash=new SplashProgressBar(5000,ui->progressBar_4,NULL);
    m_splash->show();
    m_splash->finish(this);
    ui->DFFBtn->setEnabled(true);
}
void HemodialysisDialog::drawRoundProgress(){
    m_fillBar=new RoundProgressBar(this);
    m_fillBar->setInColor(QColor(175,209,224));
    m_fillBar->setOutColor(QColor(235,244,249));
    ui->gridLayout->addWidget(m_fillBar,0,0);

    m_startBar=new RoundProgressBar(this);
    m_startBar->setInColor(QColor(170,75,70));
    m_startBar->setOutColor(QColor(249,200,200));
    ui->gridLayout->addWidget(m_startBar,0,1);
}
void HemodialysisDialog::on_emergencyBtn_clicked()
{
    ui->pic->setStyleSheet("border-image:url(:/new/prefix1/images/danger.png);");
}

void HemodialysisDialog::on_DFFBtn_clicked()
{
    m_fillBar->setValue(100);
    ui->startbBtn->setEnabled(true);
}

void HemodialysisDialog::on_startbBtn_clicked()
{
    m_startBar->setValue(100);
}
